import java.util.Scanner;
public class test2 {
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个数：" );
        long n = scanner.nextLong();
        System.out.println("n的阶乘是：" + DiJieCheng(n));

        /*char a = 'A';
        char b = 'B';
        char c = 'C';
        HangNuoTa(3, a, b, c);*/

        /*int n = 1234;
        SunXu(n);*/

        /*Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个数：");
        int n = scanner.nextInt();
        System.out.println(Sum(n));*/

        /*Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个数:");
        int n = scanner.nextInt();
        System.out.println("组成它的数之和是：" + Sum1(n));*/

        /*Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个数：");
        int n = scanner.nextInt();
        System.out.println(FeiboNaQie(n));*/



    }
    //递归求 N 的阶乘
    public static long DiJieCheng(long n) {
        if(n == 1 || n == 0) {
            return 1;
        }else {
            return n = n * (DiJieCheng(n - 1));
        }
    }
    //递归求解汉诺塔问题
    public static void HangNuoTa(int n,char a, char b, char c) {
        if( n == 1) {
            System.out.println("Move disk " + n + " from " + a + " to " + c);
            return;
        }
        HangNuoTa(n-1, a, c, b);
        System.out.println("Move disk " + n + " from " + a + " to " + c);
        HangNuoTa(n-1, c, b, a);
    }
    //递归按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4)
    public static void SunXu(int n) {
        //小于十直接打印n
        if(n < 10) {
        System.out.print(n + " ");
        }else {
            //调用SunXu，每次除十去掉最后一位，直到n小于10，开始返回
            SunXu(n / 10) ;
            System.out.print(n % 10 + " ");//%10得到最后一位数字
        }
    }
    //递归求 1 + 2 + 3 + ... + 10
    public static int  Sum(int n) {
        //判断n是否小于等于1
        if(n <= 1) {
            return n;//是的话返回n
        }else {
            return Sum(n - 1) + n;//调用自己进行递归操作，每次n-1，直到n等于1，开始回归
        }
    }
    //写一个递归方法，输入一个非负整数，返回组成它的数字之和. 例如，输入 1729, 则应该返回1+7+2+9，它的和是19
    public static int Sum1(int n) {
        if(n < 10) {
            return n;
        }else {
            return Sum1(n / 10) + n % 10;
        }
    }
    //求斐波那契数列的第 N 项
    public static int FeiboNaQie(int n) {
        if(n <= 1) {
            return n;
        } else {
            return FeiboNaQie(n - 1) + FeiboNaQie(n - 2);
        }
    }
}
